<?php

	/* _smuoiUserInterface is a base common to _smuoiAppInterface and the Screen */

	class _smuoiUserInterface{
		
		// on __construct, symlink created from application resource directory to subdir of DESKROOT/@public
		function public_resources_link($privat_dir, $public_dir){
			if(is_link($public_dir)){
				if(readlink($public_dir) == $privat_dir) return;
				unlink($public_dir);
			}
			$dir_above = dirname($public_dir);
			while(!is_dir($dir_above)){
				if(!@mkdir($dir_above)) $dir_above = dirname($dir_above);
				else $dir_above = dirname($public_dir);
			}
			exec("ln -s \"$privat_dir\" \"$public_dir\"");
		}

####	OVERWRITABLE METHODS

		function title(){
			return 'SMUOI ';	
		}
		
		function description(){
			return 'Untitled Application';	
		}

####	GENERIC METHODS	
	
		function parse_include($file, $fp=false, $sw=false){
			if(!$fp) $file = $this->incpath($file);
			ob_start();
			include $file;
			$s = ob_get_clean();
			if($sw) $s = str_replace(array("\n", "\t"), '', preg_replace('/\s\s+/', ' ', $s));
			ob_start();
			return $s;
		}
		
		function try_include($inc){
			if(!is_file($this->incpath($inc))) return '';
			return $this->parse_include($inc);
		}
	
		// run_screen can now be used to run screens intended for Ajax
		function run_screen($cxt){
			// run.php always runs first
			$this->try_include("Screens/$cxt/run.php");
			// goes to appropriate output buffer
			if($js = $this->try_include("Screens/$cxt/javascript.js")) OB()->jsln($js);
			// GUI includes
			if(!DOAJAX){
				if($css = $this->try_include("Screens/$cxt/style.css")) OB()->cssln($css);
				$sb = $this->try_include("Screens/$cxt/sidebar.php") ; 
				$mc = $this->try_include("Screens/$cxt/maincell.php");
				if($sb || $mc) OB()->mkbody($sb, $mc);
			}
			OB()->flush();
		}

####	GUI METHODS
		
		function icon($name=false, $size='128'){
			return $this->file_uri($name, "/images/$size");
		}
		
		function inc_js($filename){
			DskJs()->include_before('script', $this->file_uri($filename, '/js'));
		}
		
		function inc_css($filename){
			OB()->add_css($this->file_uri($filename, '/css'));
		}	
				
	}

